package alogrithm;

import java.util.List;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/11/21 21:46
 */
public class MaxDepth {
    public int maxDepth(Node root) {

        if (root == null) {
            return 0;
        }
        int maxChildDepth = 0;
        for (Node child : root.children) {
            int childDepth = maxDepth(child);
            maxChildDepth = Math.max(childDepth, maxChildDepth);
        }

        return maxChildDepth + 1;
    }

    ;

    class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

}
